package com.master.equipment.aep;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.ctg.ag.sdk.biz.AepDeviceCommandClient;
import com.ctg.ag.sdk.biz.AepDeviceCommandLwmProfileClient;
import com.ctg.ag.sdk.biz.aep_device_command.CreateCommandRequest;
import com.ctg.ag.sdk.biz.aep_device_command.QueryCommandListRequest;
import com.ctg.ag.sdk.biz.aep_device_command.QueryCommandListResponse;
import com.ctg.ag.sdk.biz.aep_device_command_lwm_profile.CreateCommandLwm2mProfileRequest;
import com.ctg.ag.sdk.biz.aep_device_command_lwm_profile.CreateCommandLwm2mProfileResponse;

public class Test {

	public void testApi() throws Exception {

		AepDeviceCommandClient client = AepDeviceCommandClient.newClient().appKey("3TAehmhWbf1").appSecret("JG1Kje3pqC")
				.build();

		Map<String, Object> map = new HashMap<>();
		map.put("content", map);
		map.put("deviceId", "0b6e371f45f44396858ba11fd771881e");
		map.put("operator", map);
		map.put("productId", map);
		map.put("ttl", map);
		map.put("deviceGroupId", map);
		map.put("level", map);

		CreateCommandRequest request = new CreateCommandRequest();
		// set your request params here
		request.setParamMasterKey("953367899fe94647a379dee9ca75d04b"); // single value
		request.setBody("${body}".getBytes()); // 具体格式见前面请求body说明
		System.out.println(client.CreateCommand(request));

		// more requests

		client.shutdown();

	}

	public void queryApi() throws Exception {

		AepDeviceCommandClient client = AepDeviceCommandClient.newClient().appKey("3TAehmhWbf1").appSecret("JG1Kje3pqC")
				.build();

		QueryCommandListRequest request = new QueryCommandListRequest();
		// set your request params here
		request.setParamMasterKey("953367899fe94647a379dee9ca75d04b"); // single value
		request.setParamProductId(17123003); // single value
		request.setParamDeviceId("0b6e371f45f44396858ba11fd771881e"); // single value
		request.setParamStartTime(null); // single value
		request.setParamEndTime(null); // single value
		request.setParamPageNow(null); // single value
		request.setParamPageSize(null); // single value

		QueryCommandListResponse object = client.QueryCommandList(request);
		byte[] bytes = object.getBody();

		String str = new String(bytes, "UTF-8");

		System.out.println("111111111111111111111：" + str);

		// more requests

		client.shutdown();

	}
	
	

//{
//	"command": {
//      "serviceId": "alarmDectector",
//		"method": "cmd",
//		"paras": {
//			"data":"070201",
//			"dataLen":"3"
//		}
//	},
//	"deviceId": "0b6e371f45f44396858ba11fd771881e",
//	"operator": "李",
//	"productId": 17123003,
//	"ttl": 0,
//	"deviceGroupId": 100,
//	"level": 1
//}

	public void createApi1() throws Exception {
		Map<String, Object> paras = new HashMap<>();
		paras.put("data", "070201");
		paras.put("dataLen", 3);

		Map<String, Object> commandMap = new HashMap<>();
		commandMap.put("serviceId", "alarmDectector");
		commandMap.put("method", "cmd");
		commandMap.put("paras", paras);
		
		Map<String, Object> map = new HashMap<>();
		map.put("deviceId", "0b6e371f45f44396858ba11fd771881e");
		map.put("operator", "李");
		map.put("productId", 17123003);
		map.put("ttl", 0);
		map.put("deviceGroupId",100);
		map.put("level", 1);
		map.put("command", commandMap);
		
		
		
		
	    AepDeviceCommandLwmProfileClient client = AepDeviceCommandLwmProfileClient.newClient()
	.appKey("3TAehmhWbf1").appSecret("JG1Kje3pqC")
	.build();

		CreateCommandLwm2mProfileRequest request = new CreateCommandLwm2mProfileRequest();
		// set your request params here
		request.setParamMasterKey("953367899fe94647a379dee9ca75d04b");	// single value
		request.setBody(JSONObject.toJSONString(map).getBytes());	//具体格式见前面请求body说明
		
		CreateCommandLwm2mProfileResponse object = client.CreateCommandLwm2mProfile(request);
		byte[] bytes = object.getBody();
		

		String str = new String(bytes, "UTF-8");
		System.out.println("111111111111111111111：" + str);
		
		// more requests

		client.shutdown();

	}
	
	public void createApi() throws Exception {
		Map<String, Object> paras = new HashMap<>();
		paras.put("data", "020101");
		paras.put("dataLen", "3");

		Map<String, Object> commandMap = new HashMap<>();
		commandMap.put("serviceId", "alarmDectector");
		commandMap.put("method", "cmd");
		commandMap.put("paras", paras);
		
		Map<String, Object> map = new HashMap<>();
		map.put("deviceId", "0564f8a4f2a94e0b8fbb8d1433c69d22");
		map.put("operator", "李");
		map.put("productId", 17122990);
		map.put("ttl", 0);
		map.put("deviceGroupId","");
		map.put("level", 1);
		map.put("command", commandMap);
		
		
		
		
	    AepDeviceCommandLwmProfileClient client = AepDeviceCommandLwmProfileClient.newClient()
	.appKey("3TAehmhWbf1").appSecret("JG1Kje3pqC")
	.build();

		CreateCommandLwm2mProfileRequest request = new CreateCommandLwm2mProfileRequest();
		// set your request params here
		request.setParamMasterKey("cda5ba1245704639bc0a702a49c44228");	// single value
		request.setBody(JSONObject.toJSONString(map).getBytes());	//具体格式见前面请求body说明
		
		CreateCommandLwm2mProfileResponse object = client.CreateCommandLwm2mProfile(request);
		byte[] bytes = object.getBody();
		

		String str = new String(bytes, "UTF-8");
		System.out.println("111111111111111111111：" + str);
		
		// more requests

		client.shutdown();

	}


	public static void main(String[] args) {
		Test test = new Test();
		try {
			test.createApi();
//			test.queryApi();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}